<!--
 * @Description: 项目动态信息
 * @Author: wind-lc
 * @version: 1.0
 * @Date: 2021-09-24 14:49:43
 * @LastEditTime: 2022-09-02 16:37:28
 * @FilePath: \cscec-pms-admin\src\views\project\projectDynamicInformation\index.vue
-->
<template>
  <base-breadcrumb :title="$route.meta.title">
    <a-row
      :gutter="10"
      class="page-height"
    >
      <!-- 树搜索 -->
      <a-col
        :span="6"
        class="permission-collapsed"
        :class="{ 'permission-tree-collapsed': collapsed }"
      >
        <a-card
          :style="{ border: collapsed ? 'none' : 'border: 1px solid #e8e8e8' }"
          class="page-height-tree"
        >
          <title-name title="组织架构" />
          <PermissionTreeOrganization
            :collapsed.sync="collapsed"
            @select="handleSelect"
          />
        </a-card>
      </a-col>
      <!-- 树搜索 -->
      <a-col
        :span="18"
        class="permission-collapsed page-height-list-wrapper"
        :style="collapsed ? 'width:calc(100% - 10px)' : ''"
      >
        <!-- 搜索 -->
        <searchData
          :search-data="searchOption"
          @search="search"
        />
        <!-- 搜索 -->
        <a-card class="page-height-list">
          <!-- <title-name title="项目动态信息" /> -->
          <list-table
            ref="table"
            :columns="columns"
            :request="loadData"
            :page-keys="['pageNo', 'pageSize', 'totalSize']"
            :statistics-config="{ use: true, statistics, temp }"
            :is-show-total="false"
          >
<!--            <template-->
<!--              slot="prefix"-->
<!--              slot-scope-->
<!--            >-->
<!--              <a style="display: none" />-->
<!--            </template>-->
            <span
              slot="projectName"
              slot-scope="text"
            >
              <ellipsis
                :length="30"
                tooltip
              >{{ text }}</ellipsis>
            </span>
            <template
              slot="operation"
              slot-scope="text, record"
            >
              <MoreButton :key="timeStamp">
                <a
                  v-btnPermission="'pm_041_loo_01'"
                  @click="handleDetail(record)"
                >查看</a>

                <template v-if="record.auditStatus === 'DRAFT' || record.auditStatus === 'REJECTED'">
                  <a-divider
                    v-btnPermission="'pm_041_edi_02'"
                    type="vertical"
                  />
                  <a
                    v-btnPermission="'pm_041_edi_02'"
                    @click="handleUpdate(record)"
                  >编辑</a>
                </template>

                <template v-if="
                    record.auditStatus === 'PAST' ||
                    record.auditStatus === 'REJECTED' ||
                    record.auditStatus === 'SUBMITTED'
                  ">
                  <a-divider type="vertical" />
                  <a @click="$bus.$emit('showApprovalDetailsDialog', record.id)">审批信息</a>
                </template>
              </MoreButton>
              <!-- 编辑按钮就是待提交和审批不通过才有
                审批信息的按钮就是审核通过和不通过才有
                DRAFT：待提交
                SUBMITTED：审核中
                PAST：审核通过
                REJECTED：审核不通过 -->
            </template>
          </list-table>
        </a-card>
      </a-col>
    </a-row>
  </base-breadcrumb>
</template>
<script>
import PermissionTreeOrganization from '@/components/businessComponents/PermissionTreeOrganization'
import { searchOption, columns } from './model.js'
import projectDynamicInformation from '@/api/projectDynamicInformation'
import { Ellipsis } from '@/components'
import MoreButton from '@/components/MoreButton'
export default {
  name: 'ProjectDynamicInformation',
  components: {
    PermissionTreeOrganization,
    Ellipsis,
    MoreButton
  },
  data() {
    return {
      // 收缩展开树
      collapsed: false,
      //组织架构选中项
      select: null,
      // 查询参数
      searchData: {},
      // 搜索选项
      searchOption,
      // 表头
      columns,
      // 统计
      statistics: {
        total: 0
      },
      timeStamp: new Date().getTime(),
      // 统计模板
      temp: () => {
        return <span style="margin-right: 12px">总数量：{this.statistics.total}</span>
      },
      //表格数据加载
      loadData: async (q) => {
        const obj = {}
        try {
          // if (!this.select) {
          //   return
          // }
          // 二级-分公司id
          if (this.select?.tageCode === 'BC') {
            obj.branchComId = this.select.orgId
          }
          // 三级-项目id
          if (this.select?.tageCode === 'PD') {
            obj.projectId = this.select.projectId
          }
          let searchData = Object.assign(q, { query: { ...obj, ...this.searchData } })
          const res = await projectDynamicInformation.query(searchData)
          if (res.code === 200) {
            this.statistics.total = res.totalSize
            this.$nextTick(() => {
              this.timeStamp = new Date().getTime()
            })
            return { code: 200, data: res.data, ...res }
          } else {
            return { code: 200, data: [] }
          }
        } catch (error) {
          console.log(error)
          return { code: 200, data: [] }
        }
      }
    }
  },
  methods: {
    /**
     * @description: 搜索
     * @param {Object} value 搜索数据
     * @return {Void}
     */
    search(value) {
      this.searchData = value || {}
      this.$refs.table.refresh(true)
    },
    /**
     * @description: 树选中
     * @param {object} node 节点对象
     * @return {void}
     */
    handleSelect(node) {
      console.log(node)
      this.select = node
      this.search()
      // this.$refs.table.getData(null, true)
    },
    /**
     * @description: 查看
     * @param {object} record 行数据
     * @return {void}
     */
    handleDetail(record) {
      this.$router.push({
        path: '/project/projectDynamicInformation/projectManager',
        query: {
          id: record.id,
          isProSubProject: record.isProSubProject,
          pageType: 'detail'
        }
      })
    },
    /**
     * @description: 编辑
     * @param {object} record 行数据
     * @return {void}
     */
    handleUpdate(record) {
      if (record.isProSubProject == 1 && record.isEdit != 1) {
        return this.$message.error('请先填写该专业项目对应的总承包项目的动态信息')
      }
      this.$router.push({
        path: '/project/projectDynamicInformation/projectManager',
        query: {
          id: record.id,
          isProSubProject: record.isProSubProject,
          pageType: 'update'
        }
      })
    }
  }
}
</script>
<style lang="less" scoped>
</style>
